/*
 * @Author: CodeHare
 * @Date: 2023-10-14 11:33:39
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2024-03-04 10:25:30
 * @Description: 电池保护参数设置
 */

import 'package:bruno/bruno.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yt_devops/pages/devices/device_tab/device_detail/ems/rectangle_ems_romote_control/rectangle_battery_protection_parameter/rectangle_battery_protection_parameter_model.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/styles/styles.dart';
import 'rectangle_battery_protection_parameter_controller.dart';

// ignore: must_be_immutable
class RectangleBatteryProtectionParameterWidget
    extends GetView<RectangleBatteryProtectionParameterController> {
  int deviceId;

  @override
  final controller = Get.put(RectangleBatteryProtectionParameterController());

  RectangleBatteryProtectionParameterWidget({
    super.key,
    required this.deviceId,
  });

  @override
  Widget build(BuildContext context) {
    return GetBuilder<RectangleBatteryProtectionParameterController>(
      builder: (controller) => _listBody(context),
    );
  }

  Widget _listBody(BuildContext context) {
    return Stack(
      children: <Widget>[
        BrnNormalFormGroup(
          title: 'siteMonitor.batteryProtectionParameterSet'.tr, // '电池保护参数设置',
          error: ResKey.errorTips.tr,
          isEdit: true,
          children: <Widget>[
            ...controller.model.parameterMap!.keys.map(
              (key) {
                ParameterInfoItem item = controller.model.parameterMap![key]!;

                return Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    Expanded(
                      child: BrnTextInputFormItem(
                        controller: item.textEditingController,
                        title: item.label,
                        hint: ResKey.plsInput.tr,
                        inputType: BrnInputType.decimal,
                        isRequire: true,
                        error: item.error,
                        themeData: BrnFormItemConfig(
                          titleTextStyle: BrnTextStyle(
                            fontSize: 14.sp,
                          ),
                          hintTextStyle: BrnTextStyle(
                            fontSize: 14.sp,
                          ),
                        ),
                      ),
                    ),
                    Padding(
                      padding: EdgeInsets.only(left: 5.w, right: 16.w),
                      child: Text(
                        item.unit,
                        style: TextStyle(
                          color: Colour.mainTextColor,
                          fontSize: 14.sp,
                        ),
                      ),
                    ),
                  ],
                );
              },
            ),
          ],
        ),
        Positioned(
          right: 16.w,
          child: GestureDetector(
            onTap: () {
              controller.beforeSendCommand();
              if (controller.pass) {
                controller.sendCommand(context);
              }
            },
            child: Container(
              alignment: Alignment.center,
              padding: const EdgeInsets.only(top: 15),
              child: Text(
                ResKey.deviceParameterSetting.tr,
                textAlign: TextAlign.center,
                style: TextStyle(
                  color: Colour.primaryColor,
                  fontSize: 16.sp,
                  fontWeight: FontWeight.w500,
                ),
              ),
            ),
          ),
        ),
      ],
    );
  }
}
